package com.ymatou.iapi.coupon.testcase;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.coupon.parameter.batchInfo;
import com.ymatou.iapi.coupon.parameter.getAllSellerValidBatchesBean;
import com.ymatou.iapi.coupon.service.getAllSellerValidBatchesCall;
import com.ymatou.iapi.coupon.service.getAllSellerValidBatchesCall.batchDtoInfo;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.model.couponusecondition;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.database.sqlwapper.couponuseconditionWapper;
/**
*获取所有买手有效的批次
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getAllSellerValidBatches{
	private static getAllSellerValidBatchesBean getallsellervalidbatchesBean;
	private static getAllSellerValidBatchesCall getallsellervalidbatchesCall;
	private couponbatchWapper couponbatchWapper=new couponbatchWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取所有买手有效的批次");
	}

	@Before
	public void caseUp() {
		getallsellervalidbatchesBean=new getAllSellerValidBatchesBean();
		getallsellervalidbatchesCall=new getAllSellerValidBatchesCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getallsellervalidbatchesCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_getAllSellerValidBatches_001() {
		Logger.start(true,"获取所有买手有效的批次(数据量太大,better平台跑挂)");
		try {
			getallsellervalidbatchesCall.setData(getallsellervalidbatchesBean);
			getallsellervalidbatchesCall.callService();	
			verifyBatchInfos();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	private void verifyBatchInfos()
    {
		batchDtoInfo batchInfos = getallsellervalidbatchesCall.getSellerBatchInfos();
		List<Map> db_Map=couponbatchWapper.getAllSellerValidBatchs();
        Logger.verifyEquals(db_Map.size(), batchInfos.getBatchDtos().size(), "验证返回的长度与数据库查询的一致");
        for (int i = 0; i < batchInfos.getBatchDtos().size() ; i++) {
        	batchInfo batchInfo = batchInfos.getBatchDtos().get(i);
        	Logger.comment("验证batchId="+ batchInfo.getBatchId());
            couponbatch batch = new couponbatchWapper().selectBybatchCode(batchInfo.getBatchCode()).get(0);
            
            Logger.verifyEquals(batch.getOperatorId(), batchInfo.getSellerId(), "验证第"+(i+1)+"条返回SellerId为正常");
            Logger.verifyEquals(batch.getBatchId(), batchInfo.getBatchId(), "验证第"+(i+1)+"条返回BatchId为正常");
            Logger.verifyEquals(batch.getBatchCode(), batchInfo.getBatchCode(), "验证第"+(i+1)+"条返回batchcode为正常");
            Logger.verifyEquals(batch.getTotalNum(), batchInfo.getCouponCount(), "验证第"+(i+1)+"条返回CouponCount为正常");
            Logger.verifyEquals(batch.getReceivedCount(), batchInfo.getReceivedCount(), "验证第"+(i+1)+"条返回ReceivedCount为正常");
            Logger.verifyEquals(batch.getCouponValue().stripTrailingZeros().toString(),
            		batchInfo.getCouponValue().stripTrailingZeros().toString(), "验证第"+(i+1)+"条返回CouponValue为正常");
            Logger.verifyEquals(batch.getMinOrderValue().stripTrailingZeros().toString(),
            		batchInfo.getMinOrderValue().stripTrailingZeros().toString(), "验证第"+(i+1)+"条返回MinOrderValue为正常");
            Logger.verifyEquals(batch.getCouponType(), batchInfo.getCouponType(), "验证第"+(i+1)+"条返回CouponType为正常");
            Logger.verifyEquals(batch.getCouponTypeBizValue(), batchInfo.getCouponTypeBizValue(), "验证第"+(i+1)+"条返回CouponTypeBizValue为正常");
            Logger.verifyEquals(getDateString(batch.getValidStart()), batchInfo.getValidStart(), "验证第"+(i+1)+"条返回ValidStart为正常");
            Logger.verifyEquals(getDateString(batch.getValidEnd()), batchInfo.getValidEnd(), "验证第"+(i+1)+"条返回ValidEnd为正常");
            Logger.verifyEquals(getDateString(batch.getAcquireStartTime()), batchInfo.getAcquireStartTime(), "验证第"+(i+1)+"条返回AcquireStartTime为正常");
            Logger.verifyEquals(getDateString(batch.getAcquireEndTime()), batchInfo.getAcquireEndTime(), "验证第"+(i+1)+"条返回AcquireEndTime为正常");
            
            Logger.verifyEquals(batch.getMinOrderValue().equals(new BigDecimal(0))?true:false, 
            		batchInfo.getIsNoThreshold(), "验证第"+(i+1)+"条返回IsNoThreshold为正常");
        }
    }
    
	
    private String getDateString(Date date) {
        SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");

        return formatter1.format(date) + "T" + formatter2.format(date);
    }
}